﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Kokomo.PeInspector.Reflection
{
	class TextCodeWriter : CodeWriterBase
	{
		public TextWriter TextWriter { get; private set; }

		public TextCodeWriter(
			TextWriter textWriter
			)
		{
			if (textWriter == null) throw new ArgumentNullException("textWriter");

			this.TextWriter = textWriter;
		}

		public int CurrentLineIndex { get; private set; }
		public int CurrentCharacterIndex { get; private set; }

		protected override void WriteTextOverride(string text, CodeTextType textType)
		{
			this.CurrentCharacterIndex += text.Length;
			this.TextWriter.Write(text);
		}

		protected override void WriteMemberReferenceOverride(object target, string text, CodeTextType textType)
		{
			this.CurrentCharacterIndex += text.Length;
			this.TextWriter.Write(text);
		}

		protected override void WriteLineBreakOverride()
		{
			this.CurrentLineIndex++;
			this.CurrentCharacterIndex = 0;
			this.TextWriter.WriteLine();
		}
	}
}
